package edu.tjpu.share.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;

public class NetworkUtil {
	public static boolean isAccessToInternet(Context c) {
		ConnectivityManager cManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = cManager.getActiveNetworkInfo();
		if (info != null && info.isAvailable()) {
			return true;
		} else {
			return false;
		}
	}
	
    public static boolean CheckMobileNetworkState(Context c)
    {
        boolean flag = false;
        ConnectivityManager manager = (ConnectivityManager)c.getSystemService(
                Context.CONNECTIVITY_SERVICE);
        State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        if(manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)!=null){
        State mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
        
        
        if(mobile == State.CONNECTED||mobile==State.CONNECTING)
        {
        	flag = true;
        }
        }
        if(wifi == State.CONNECTED||wifi==State.CONNECTING){
        	flag = false;
        }
        return flag;
    }
}
